﻿Public Class frmHolidayBR
    Private frmParent As frmMain
    Dim validator As PropertyValidator = New PropertyValidator
    Dim payrollManager As New PayrollManager

    Private Sub frmHolidayBR_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.MdiParent = frmMain
        ClearAllFields()
        Try
            Dim holList As List(Of Holiday) = payrollManager.getAllHoliday()
            For Each hol As Holiday In holList
                Dim item As ListViewItem
                item = lvwHoliday.Items.Add(hol.description)
                item.SubItems.Add(hol.holiday_date)
                item.SubItems.Add(If((hol.type = 1), "Legal", "Special"))
                item.SubItems.Add(hol.id)
            Next
            grpHoliday.Text = "Total Record(s): " + lvwHoliday.Items.Count.ToString()
            validator.resizes(lvwHoliday)
        Catch ex As Exception
            MsgBox("Can't lod Web page" & vbCrLf & ex.Message)
        End Try
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        frmHolidayDE.ShowDialog()
        frmHolidayBR_Load(vbNull, EventArgs.Empty)
    End Sub
    Public Function ClearAllFields()
        validator.ResetControls(grpHoliday)
        btnAdd.Enabled = True
        btnEdit.Enabled = False
        btnDelete.Enabled = False
        grpHoliday.Text = "Total Record(s): 0"
        validator.resizes(lvwHoliday)
        Clipboard.Clear()
        Return 0
    End Function

    Private Sub lvwHoliday_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvwHoliday.SelectedIndexChanged
        btnEdit.Enabled = (lvwHoliday.SelectedItems.Count = 1)
        btnDelete.Enabled = (lvwHoliday.SelectedItems.Count > 0)
    End Sub

    Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Clipboard.SetText(lvwHoliday.SelectedItems(0).SubItems(3).Text)
        frmHolidayDE.ShowDialog()
        frmHolidayBR_Load(vbNull, EventArgs.Empty)
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Try
            For i As Integer = 1 To lvwHoliday.SelectedItems.Count
                'sqlManager.executeQuery("DELETE FROM tbl_philhealth WHERE id = " + lvwPHI.SelectedItems(i - 1).SubItems(6).Text)
                payrollManager.deleteItemHoliday(lvwHoliday.SelectedItems(i - 1).SubItems(3).Text)
            Next
            MsgBox("Record(s) has been deleted.")
            frmHolidayBR_Load(vbNull, EventArgs.Empty)
            grpHoliday.Text = "Total Record(s): " + lvwHoliday.Items.Count.ToString()
        Catch ex As Exception
            MsgBox("Can't load Web page" & vbCrLf & ex.Message)
        End Try
    End Sub
End Class